#ifndef _SHADOW_SMYSQL_MYSQL_CONN_POOL_H_
#define _SHADOW_SMYSQL_MYSQL_CONN_POOL_H_

#include <vector>
#include <string>

#include <log4cxx/logger.h>
#include <log4cxx/xml/domconfigurator.h>

#include <mysql.h>

#include "ResourcePool.h"

using std::vector;
using std::string;

typedef struct _MYSQL_CONN {
		MYSQL * mysql;
		int index;
} MYSQL_CONN;

class MysqlConnPool {
		public:
				MysqlConnPool();
				~MysqlConnPool();

				int init(int pool_num, const char *mysqld_host, int mysqld_port, const char * mysqld_db, \
								const char * mysqld_user, const char * mysqld_passwd);
				MYSQL_CONN * acquire_conn();
				int release_conn(MYSQL_CONN *);
		protected:
				int reconnect_mysql_resource(MYSQL_CONN & conn);
				bool is_extra_mysql_conn(MYSQL_CONN * pc);
				MYSQL_CONN * alloc_extra_conn();
				int free_extra_conn(MYSQL_CONN * pc);
		private:
				ResourcePool _res_pool;
				vector<MYSQL_CONN> _conns;
				string _mysqld_host;
				int _mysqld_port;
				string _mysqld_db;
				string _mysqld_user;
				string _mysqld_passwd;
				log4cxx::LoggerPtr _logger;
};
#endif
